package asteroids.model.expressions;


import exceptions.*;

/**
 * A subclass of expression (E) that represents the the And (&&) comparison
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public class And extends BooleanComparison {
	
	public And(E e1, E e2) {
		super(e1, e2);
	}

	@Override
	public Boolean getValue() throws IllegalOperandException {
		if(!this.isValidExpression()) { throw new IllegalOperandException(); }
		boolean left = ((Boolean)getLeftOperand().getValue());
		boolean right = ((Boolean)getRightOperand().getValue());
		return left && right;
	}
	
	@Override
	public String toString() {
		return getLeftOperand().toString() + " && " + getRightOperand().toString(); 
	}

	@Override
	public E createCopy() {
		return new And(getLeftOperand().createCopy(), getRightOperand().createCopy());
	}
	
}
